﻿using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using WiTeach.CourseManagement.Model;
using WiTeach.Tools;
using MySql.Data.MySqlClient;
using System.Data;


namespace WiTeach.CourseManagement.ViewModel
{
    /// <summary>
    /// 课程集合数据模型
    /// </summary>
    public class CourseCollection:INotifyPropertyChanged
    {
        public ObservableCollection<Course> Courses = new ObservableCollection<Course>();
        
        public CourseCollection()
        {
            DataTableToCourseModel();
        }

        public ObservableCollection<Course> CourseList {

            get {
                return Courses;
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        public ObservableCollection<Course> DataTableToCourseModel()
        {
            
            string sql = "select * from lesson_manage_table";
            DataTable dataTable = SqlHelper.ExecuteDataTable(sql, new MySqlParameter[0]);
            foreach (DataRow dt in dataTable.Rows)
            {
                Course courseInfo = new Course();
                courseInfo.Lesson_ID = Convert.ToInt16(dt["Lesson_ID"]);
                courseInfo.Lesson_Name = dt["Lesson_Name"].ToString();
                //courseInfo.LessonType_ID = Convert.ToInt16(dt["LessonType_ID"]);
                //courseInfo.Host_ID = Convert.ToInt16(dt["Host_ID"]);
                //courseInfo.InputUser_ID = Convert.ToInt16(dt["InputUser_ID"]);
                //courseInfo.Input_Time = dt["Input_Time"].ToString();
                //courseInfo.AlterUser_ID = Convert.ToInt16(dt["AlterUser_ID"]);
                //courseInfo.Alter_Time = dt["Alter_Time"].ToString();
                Courses.Add(courseInfo);
            }
            return Courses;
 
        }


        //public ObservableCollection<Course> DataTableToCourseModel


    

    }

}
